<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>
        云客客户关系管理系统
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/static/css/x-admin.css" media="all">
</head>

<div class="x-body">
    <form class="layui-form">
    <div class="layui-form-item">
        <label for="userName" class="layui-form-label">
            用户编号
        </label>
        <div class="layui-input-inline">
            <input type="text" id="userId" name="userId" required="" lay-verify="required" readonly="readonly"
                   autocomplete="off" class="layui-input" value="${user.id}">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="userName" class="layui-form-label">
            用户名称
        </label>
        <div class="layui-input-inline">
            <input type="text" id="userName" name="userName" required="" lay-verify="required"
                   autocomplete="off" class="layui-input" value="${user.name}">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="L_pass" class="layui-form-label">
            用户密码
        </label>
        <div class="layui-input-inline">
            <input type="password" id="L_pass"  name="password" required="" lay-verify="pass"
                   autocomplete="off" class="layui-input" value="${user.password}" >
        </div>
        <div class="layui-form-mid layui-word-aux">
            6到16个字符
        </div>
    </div>
    <div class="layui-form-item">
        <label for="role" class="layui-form-label">
           员工姓名
        </label>
        <div class="layui-input-inline">
            <select name="staffId" id="staffId">
                <option value="">请选择员工</option>
            <#list staffList as staff>
                <#if user.staffId==staff.id>
                    <option value="${staff.id}" selected>${staff.name}</option>
                <#else>
                    <option value="${staff.id}">${staff.name}</option>
                </#if>
            </#list>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label for="role" class="layui-form-label">
            部门名称
        </label>
        <div class="layui-input-inline">
            <select name="deptId" id="deptId">
                <option value="">请选择部门</option>
            <#list deptList as dept>
                <#if user.deptId==dept.id>
                    <option value="${dept.id}" selected>${dept.name}</option>
                <#else>
                    <option value="${dept.id}">${dept.name}</option>
                </#if>
            </#list>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label for="role" class="layui-form-label">
           职务名称
        </label>
        <div class="layui-input-inline">
            <select name="jobId" id="jobId">
                <option value="">请选择职务</option>
            <#list jobList as job>
                <#if user.jobId==job.id>
                    <option value="${job.id}" selected>${job.name}</option>
                <#else>
                    <option value="${job.id}">${job.name}</option>
                </#if>
            </#list>
            </select>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">创建日期：</label>
        <input type="date" name="createDate" id="createDate" width="200px"/>
    </div>
    <div class="layui-form-item">
        <label for="L_sign" class="layui-form-label">
        </label>
        <button class="layui-btn" key="set-mine" lay-filter="save" lay-submit>
            保存
        </button>
    </div>
    </form>
</div>
</body>
<script src="/static/lib/layui/layui.js" charset="utf-8">
</script>
<script src="/static/js/x-layui.js" charset="utf-8">
</script>
<script src="/static/js/vue/vue.min.js" charset="UTF-8"></script>
<script src="/static/js/jquery.min.js" charset="UTF-8"></script>
<script>
    layui.use(['form','layer'], function() {
        $ = layui.jquery;
        var form = layui.form()
                , layer = layui.layer;

        //自定义验证规则
        form.verify({
            nikename: function (value) {
                if (value.length < 5) {
                    return '昵称至少得5个字符啊';
                }
            }
            , pass: [/(.+){6,12}$/, '密码必须6到12位']
            , repass: function (value) {
                if ($('#L_pass').val() != $('#L_repass').val()) {
                    return '两次密码不一致';
                }
            }
        });
        var app=0;
        form.on('submit(save)', function () {
            $.ajax({
                type: "POST",
                dataType: "json",
                url: "/user/editUser",
                data: {
                    userId:$("#userId").val(),
                    userName: $("#userName").val(),
                    password: $("#L_pass").val(),
                    deptId: $("#deptId").val(),
                    jobId: $("#jobId").val(),
                    staffId: $("#staffId").val(),
                    createDate: $("#createDate").val()
                },
                success: function (msg) {
                    app=msg.data;
                    alert(app);
                }
            });

            if(app<0){
                layer.alert("编辑失败", {icon: 6}, function () {
                    // 获得frame索引
                    var index = parent.layer.getFrameIndex(window.name);
                    //关闭当前frame
                    parent.layer.close(index);
                });
            }else{
                layer.alert("编辑成功", {icon: 6}, function () {
                    // 获得frame索引
                    var index = parent.layer.getFrameIndex(window.name);
                    //关闭当前frame
                    parent.layer.close(index);
                });
            }
            return false;

        })
    })
</script>
</html>